<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">/Users/liyutao/Desktop/Learning Code/vue
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            height: 2000px;
        }
    </style>
</head>
<body>
    <script>
        // 节流：在某个单位时间内，同一个事件被触发多次，只有一次生效
        window.onscroll = throttle(function(){
            console.log(123)
        },500)

        function throttle(fn,wait){
            let flag = true
            return function(...args){
                if(flag){
                    setTimeout(() => {
                        fn.apply(this,args)
                        flag = true
                    },wait)
                }
                flag = false
            }
        }
    </script>
</body>
</html>